﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ServiceApplication.Service.Basic;
using CommonLibrary.DataModel.Basic;
using OAonline.Models;
using System.Workflow.Activities;
using System.Web.Security;

namespace OAonline.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        BasicService basicService = new BasicService();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult LogOn(UserModel userModel)
        {
            string login_name = Request.Form["login_name"];
            string login_psw = Request.Form["login_psw"];

            UserEntity userEntity = basicService.QueryUserByLoginid(login_name);

            if (userEntity == null)
            {
                return JavaScript("alert('登录失败,请确认账号是否正确');");
            }
            else if (userEntity.password != login_psw)
            {
                return JavaScript("alert('登录失败,请确认密码是否正确');");
            }
            else
            {
                //添加静态模板
                userModel.user = userEntity;
                FormsAuthentication.SetAuthCookie(login_name, false);//是否记住
                return JavaScript("document.location='/Home/Main'");
            }
        }

        public ActionResult LogOff(UserModel userModel)
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Index");
        }


    }
}
